/**
 * @author GhostWei
 */
var main = {
	baseUrl: '/',
	resize: function() {
		if(parent.$ && parent.$('#mainFrame').length > 0) {
			var documentWidth = $(document).width();
			var mainFrame = parent.$('#mainFrame');
			var mainFrameWidth = mainFrame.width();
			if(documentWidth > mainFrameWidth) {
				parent.$('#mainFrame').css({"overflow-x" : "scroll"});
			} else {
				parent.$('#mainFrame').css({"overflow-x" : "hidden"});
			}
		}
	},
	winopen: function(link) {
		window.open(link.attr('href'), '_blank', 'toolbar=no,menubar=no,scrollbars=yes,z-look=yes,location=no');
		return false;
	},
	init: function() {
		this.resize();
		$(window).resize(function(){main.resize();});
		$('.batch,.collect').css({'cursor':'pointer'}).click(function(){return main.winopen($(this));});
	}
};
$(document).ready(function(){main.init();});

function print_r(array) {
	var output = '', pad_char = ' ', pad_val = 4,
	getFuncName = function (fn) {
		var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
		if (!name) {
			return '(Anonymous)';
		}
		return name[1];
	},
	repeat_char = function (len, pad_char) {
		var str = '';
		for (var i = 0; i < len; i++) {
			str += pad_char;
		}
		return str;
	},
	formatArray = function (obj, cur_depth, pad_val, pad_char) {
		if (cur_depth > 0) {
			cur_depth++;
		} 
		var base_pad = repeat_char(pad_val * cur_depth, pad_char);
		var thick_pad = repeat_char(pad_val * (cur_depth + 1), pad_char);
		var str = '';
		if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') {
			str += 'Array\n' + base_pad + '(\n';
			for (var key in obj) {
				if (Object.prototype.toString.call(obj[key]) === '[object Array]' || Object.prototype.toString.call(obj[key]) === '[object Object]') {
					str += thick_pad + '[' + key + '] => ' + formatArray(obj[key], cur_depth + 1, pad_val, pad_char);
				} else {
					str += thick_pad + '[' + key + '] => ' + obj[key] + '\n';
				}
			}
			str += base_pad + ')\n';
		} else if (obj === null || obj === undefined) {
			str = '';
		} else {
			str = obj.toString();
		}
		return str;
	};
 
	output = formatArray(array, 0, pad_val, pad_char);
	return output;
}
